var getResponsiveBreakpoint = function (size) { // bootstrap responsive breakpoints var sizes = { 'xs': 480, // extra small 'sm': 768, // small 'md': 992, // medium 'lg': 1200 // large }; return sizes[size] ? sizes[size] : 0; }; var Layout = function () { var resBreakpointMd = getResponsiveBreakpoint('md'); // Handles the go to top button at the footer var handleGoTop = function () { var offset = 300; var duration = 500; if (navigator.userAgent.match(/iPhone|iPad|iPod/i)) { // ios supported $(window).bind("touchend touchcancel touchleave", function (e) { if ($(this).scrollTop() > offset) { $('.scroll-to-top').fadeIn(duration); } else { $('.scroll-to-top').fadeOut(duration); } }); } else { // general $(window).scroll(function () { if ($(this).scrollTop() > offset) { $('.scroll-to-top').fadeIn(duration); } else { $('.scroll-to-top').fadeOut(duration); } }); } $('.scroll-to-top').click(function (e) { e.preventDefault(); $('html, body').animate({ scrollTop: 0 }, duration); return false; }); }; // Set proper height for sidebar and content. The content and sidebar height must be synced always. var handleSidebarAndContentHeight = function () { var content = $('.page-content'); var sidebar = $('.page-sidebar'); var body = $('body'); var height; if (body.hasClass("page-footer-fixed") === true && body.hasClass("page-sidebar-fixed") === false) { var available_height = Layout.getViewPort().height - $('.page-footer').outerHeight() - $('.page-header').outerHeight(); if (content.height() < available_height) { content.attr('style', 'min-height:' + available_height + 'px'); } } else { if (body.hasClass('page-sidebar-fixed')) { height = _calculateFixedSidebarViewportHeight(); if (body.hasClass('page-footer-fixed') === false) { height = height - $('.page-footer').outerHeight(); } } else { var headerHeight = $('.page-header').outerHeight(); var footerHeight = $('.page-footer').outerHeight(); if (Layout.getViewPort().width < resBreakpointMd) { height = Layout.getViewPort().height - headerHeight - footerHeight; } else { height = sidebar.height() + 20; } if ((height + headerHeight + footerHeight) <= Layout.getViewPort().height) { height = Layout.getViewPort().height - headerHeight - footerHeight; } } content.attr('style', 'min-height:' + height + 'px'); } }; var handleQuickSidebarToggler = function () { // quick sidebar toggler // $('.dropdown-quick-sidebar-toggler a, .page-quick-sidebar-toggler, .quick-sidebar-toggler').click(function (e) { // $('body').toggleClass('page-quick-sidebar-open'); // }); $('body').on('click', function (e) { if ($('.dropdown-quick-sidebar-toggler a').is(e.target) || $('.page-quick-sidebar-toggler').is(e.target) || $('.quick-sidebar-toggler').is(e.target)) { $('body').toggleClass('page-quick-sidebar-open'); }else if ($('body').hasClass('page-quick-sidebar-open') && $('.page-quick-sidebar-wrapper').has(e.target).length === 0) { $('body').toggleClass('page-quick-sidebar-open'); } }); }; // Handle sidebar menu var handleSidebarMenu = function () { // handle sidebar link click $('.page-sidebar-menu').on('click', 'li > a.nav-toggle, li > a > span.nav-toggle', function (e) { var that = $(this).closest('.nav-item').children('.nav-link'); if (Layout.getViewPort().width >= resBreakpointMd && !$('.page-sidebar-menu').attr("data-initialized") && $('body').hasClass('page-sidebar-closed') && that.parent('li').parent('.page-sidebar-menu').size() === 1) { return; } var hasSubMenu = that.next().hasClass('sub-menu'); if (Layout.getViewPort().width >= resBreakpointMd && that.parents('.page-sidebar-menu-hover-submenu').size() === 1) { // exit of hover sidebar menu return; } if (hasSubMenu === false) { if (Layout.getViewPort().width < resBreakpointMd && $('.page-sidebar').hasClass("in")) { // close the menu on mobile view while laoding a page $('.page-header .responsive-toggler').click(); } return; } if (that.next().hasClass('sub-menu always-open')) { return; } var parent = that.parent().parent(); var the = that; var menu = $('.page-sidebar-menu'); var sub = that.next(); var autoScroll = menu.data("auto-scroll"); var slideSpeed = parseInt(menu.data("slide-speed")); var keepExpand = menu.data("keep-expanded"); if (!keepExpand) { parent.children('li.open').children('a').children('.arrow').removeClass('open'); parent.children('li.open').children('.sub-menu:not(.always-open)').slideUp(slideSpeed); parent.children('li.open').removeClass('open'); } var slideOffeset = -200; if (sub.is(":visible")) { $('.arrow', the).removeClass("open"); the.parent().removeClass("open"); sub.slideUp(slideSpeed, function () { if (autoScroll === true && $('body').hasClass('page-sidebar-closed') === false) { if ($('body').hasClass('page-sidebar-fixed')) { menu.slimScroll({ 'scrollTo': (the.position()).top }); } else { Layout.scrollTo(the, slideOffeset); } } handleSidebarAndContentHeight(); }); } else if (hasSubMenu) { $('.arrow', the).addClass("open"); the.parent().addClass("open"); sub.slideDown(slideSpeed, function () { if (autoScroll === true && $('body').hasClass('page-sidebar-closed') === false) { if ($('body').hasClass('page-sidebar-fixed')) { menu.slimScroll({ 'scrollTo': (the.position()).top }); } else { Layout.scrollTo(the, slideOffeset); } } handleSidebarAndContentHeight(); }); } e.preventDefault(); }); }; // Handles the horizontal menu var handleSearchForm = function () { // handle search box expand/collapse $('.page-header').on('click', '.search-form', function (e) { $(this).addClass("open"); $(this).find('.form-control').focus(); e.preventDefault(); e.stopPropagation(); $('.page-header .search-form .form-control').on('blur', function (e) { $(this).closest('.search-form').removeClass("open"); $(this).unbind("blur"); }); }); // handle hor menu search form on enter press $('.page-header').on('keypress', '.hor-menu .search-form .form-control', function (e) { if (e.which == 13) { $(this).closest('.search-form').submit(); return false; } }); // handle header search button click $('.page-header').on('mousedown', '.search-form.open .submit', function (e) { e.preventDefault(); e.stopPropagation(); $(this).closest('.search-form').submit(); }); }; var handleFaq = function () { $(".masonry .projection-page").addClass("m_item masonry-brick"); $('.masonry').masonry({ itemSelector: '.m_item', columnWidth: 250, animationOptions: { duration: 400 } }); $('a.m_item_more').css("margin-bottom", "0px"); }; return { init: function () { handleGoTop(); handleSearchForm(); handleQuickSidebarToggler(); handleSidebarMenu(); }, initFaq: function () { handleFaq(); }, // To get the correct viewport width based on http://andylangton.co.uk/articles/javascript/get-viewport-size-javascript/ getViewPort: function () { var e = window, a = 'inner'; if (!('innerWidth' in window)) { a = 'client'; e = document.documentElement || document.body; } return { width: e[a + 'Width'], height: e[a + 'Height'] }; }, // wrApper function to scroll(focus) to an element scrollTo: function (el, offeset) { var pos = (el && el.size() > 0) ? el.offset().top : 0; if (el) { if ($('body').hasClass('page-header-fixed')) { pos = pos - $('.page-header').height(); } else if ($('body').hasClass('page-header-top-fixed')) { pos = pos - $('.page-header-top').height(); } else if ($('body').hasClass('page-header-menu-fixed')) { pos = pos - $('.page-header-menu').height(); } pos = pos + (offeset ? offeset : -1 * el.height()); } $('html,body').animate({ scrollTop: pos }, 'slow'); }, // function to scroll to the top scrollTop: function () { App.scrollTo(); } }; }(); //if (App.isAngularJsApp() === false) { jQuery(document).ready(function () { Layout.init(); }); //}